var ClubUserEditOverEvent = 'ClubUserEditOver';
var ClubUserEditScoreWindow = Window.extend({
    _ccsFileName: res.ClubUserEditScoreWindow_json,

    _currentEditType: 0,  //0是所有数据   1是查找区间数据
    initWindow: function () {
        this._refreshBtnView('btn_selectLeft');
        this._nodeList['leftValue'].setString(0);
        this._nodeList['rightValue'].setString(0);
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_selectLeft': '_changeBtnSelect',
            'btn_selectRight': '_changeBtnSelect',
            'bg_inputLeft': '_clickSearchHandler',
            'bg_inputRight': '_clickSearchHandler',
            'btn_ok': '_clickOk',
        }
    },

    _changeBtnSelect: function (target) {
        this._refreshBtnView(target.getName());
    },

    _clickSearchHandler: function (target) {
        if (this._currentEditType == 0) {
            return;
        }
        this.addChild(new ClubEditScore(this._editPanelCallBack.bind(this, target.getName())));
    },

    _refreshBtnView: function (str) {
        var selectLeft = str == 'btn_selectLeft';
        this._currentEditType = selectLeft ? 0 : 1;
        this._nodeList['btn_selectLeft.select'].setVisible(selectLeft);
        this._nodeList['btn_selectRight.select'].setVisible(!selectLeft);
        var color = cc.color(255, 255, 255);
        if (this._currentEditType == 0) {
            color = cc.color(125, 125, 125);
        }
        this._nodeList['leftValue'].setTextColor(color);
        this._nodeList['rightValue'].setTextColor(color);
    },

    _editPanelCallBack: function (inputName, str) {
        if (inputName == 'bg_inputLeft') {
            this._nodeList['leftValue'].setString(str);
        } else {
            this._nodeList['rightValue'].setString(str);
        }
    },

    _clickOk: function () {
        var leftValue = parseInt(this._nodeList['leftValue'].getString());
        var rightValue = parseInt(this._nodeList['rightValue'].getString());
        if (rightValue != 0 && leftValue > rightValue) {
            showAlert('左侧数值不能大于右侧数值!');
            return;
        }
        eventManager.dispatchEvent(ClubUserEditOverEvent, {leftValue: leftValue, rightValue: rightValue});
        this.close();
    },

});